index_app.controller("member_info_list", function ($scope,$http) {

	var grid_selector = "#grid-table";
	var pager_selector = "#grid-pager";


	$(window).on('resize.jqGrid', function() {
		$(grid_selector).jqGrid('setGridWidth', $(".page-content").width());
	});

	 $http.post("menberInfo/getSumTotal").then(function(response){
            	//数据源
            	$scope.sumTotal = response.data;
         });

	jQuery(grid_selector).jqGrid('aceInit', pager_selector, {
		url:"menberInfo/listMembefInfo",
		datatype : "json",
		colNames : ['','ID','会员名', '会员卡号','手机号','会员类别','余额', '消费总额','卡有效期'],
		colModel : [
		            {name:'myac',hidden:true},
		            {name:'memberKey',index:'memberKey', width:60,hidden:true},
		             {name:'menberName',index:'menberName', width:60},
		             {name:'vipNum',index:'vipNum', width:60},
		            {name:'vipTel',index:'vipTel', width:60},
		            {name:'vipType',index:'vipType', width:60},
		             {name:'balance',index:'balance', width:60},
		             {name:'costSum',index:'costSum', width:60},
		            {name:'carExpire',index:'carExpire', width:60 },
		            ],
		            sortable:true,
		            sortname:'memberKey',
		            sortorder:'asc',
		            caption : "<i class='menu-icon fa fa-unlock white'></i>会员信息明细"
	});
	jQuery(grid_selector).jqGrid('aceNavGrid', pager_selector);
	//});

	//查找事件
    $scope.searchMemberInfo = function(){
        $(grid_selector).jqGrid('setGridParam',{
              url:"menberInfo/searchSelf?fieldValue="+$("#memberInfo").val(),
              datatype:'json',
               page:1
        }).trigger("reloadGrid");
    }
     $scope.isExport = false;
    $scope.searchTime = function(){
        if(!checkEndTime($scope.startDate,$scope.endDate)){
            $scope.title = "警告";
            $scope.toolTip = "开始时间小于结束时间，请重新选择";
            toolTipDialog();
        } else {
            console.log($scope.startDate);
            $scope.isExport = true;
            $(grid_selector).jqGrid('setGridParam',{
                  url:"menberInfo/searchDate?startDate="+$scope.startDate+"&endDate="+$scope.endDate,
                  datatype:'json',
                  page:1
            }).trigger("reloadGrid");
            toExcel();
        }
    }

     function toExcel(){
        $scope.exportExcel = function(){
            $scope.actionStr = "/menberInfo/toDcExcel?startDate="+$scope.startDate+"&endDate="+$scope.endDate;
            $("#formExcel").attr("action", $scope.actionStr);
        }
     }

    function checkEndTime(startTime,endTime){
        $scope.start=new Date(startTime.replace("-", "/").replace("-", "/"));
        $scope.end=new Date(endTime.replace("-", "/").replace("-", "/"));

        if($scope.end < $scope.start){
            return false;
        }
        return true;
    }
function toolTipDialog(){
    		easyDialog.open({
    			container : {
    				header : $scope.title,
    				content : $scope.toolTip,
    				yesFn : $scope.toolFn,
    				noFn : false
    			},
    			fixed : false
    		});
    	}
    	//弹窗中确定按钮事件
    	$scope.toolFn = function(){
    		return true;
    	}
 $scope.refresh = function(){
    $("#memberInfo").val("");
    $("#startDate").val("");
    $("#endDate").val("");
        $(grid_selector).jqGrid('setGridParam',{
                          url:"menberInfo/listMembefInfo",
                          datatype:'json',
                           page:1
                    }).trigger("reloadGrid");
    }

})


